<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.9
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   ###############

JFX::checkAdminPermsRedirect('core', 'perm_export_page');

$THEME->addBreadcrumb($this->adminUrl.'/export/export-page', $this->lang('ap_title_export_export-page'));

$pageid = (int) get('page');


if($pageid > 0){
	// make the page
    $page = JFX_Block::getBlockById($pageid, $pageid, $USER->workspace, true, true);
	$pageExport = new JFX_Page_File;
	$pageExport->setPage($page);
	$filename = $CONFIG->tmpDir.'/page-export.'.$pageid.'.php';
	$pageExport->export($filename);

	// serve the file
	while(ob_get_level()>0) ob_end_clean();
    header('Content-type: application/jfx-page');
    header('Content-disposition: attachment; filename='.$page->getDetails('slug').'.'.date('Ymd').'.jfxp');
    readfile($filename);
    exit;

}else{
    // have to select a page to export

    $pages = JFX::getPageTree(0, $USER->workspace);

    $tree = JFX_ExportPage_MakeTree($pages);

    $tree = '<ul id="jfxcore-export-page-tree">'.$tree.'</ul>';

    echo $tree;


    $VIEW->addJs('
    $(document).ready(function(){
        $("#jfxcore-export-page-tree").treeview({
            persist: "location",
            collapsed: true,
            unique: true
        });
    });
    ');

}













